package com.bw.mallshop.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bw.mallshop.entity.HomeBannerEntity;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

public class HomeBannerAdapter extends BannerAdapter<HomeBannerEntity, HomeBannerAdapter.HomeBannerVH> {

    public HomeBannerAdapter(List<HomeBannerEntity> datas) {
        super(datas);
    }

    @Override
    public HomeBannerVH onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(lp);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new HomeBannerVH(imageView);
    }

    @Override
    public void onBindView(HomeBannerVH holder, HomeBannerEntity data, int position, int size) {
        Glide.with(holder.imageView.getContext()).load(data.imgUrl).into(holder.imageView);
    }

    public static class HomeBannerVH extends RecyclerView.ViewHolder{

        ImageView imageView;

        public HomeBannerVH(@NonNull View itemView) {
            super(itemView);
            this.imageView = (ImageView) itemView;
        }
    }

}
